import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:nft_shop/box/widget/purchase_instructions_widget.dart';
import 'package:nft_shop/login/controller/logic_controller.dart';
import 'package:nft_shop/login/controller/user_controller.dart';
import 'package:nft_shop/login/page/login_page.dart';
import 'package:nft_shop/market/conteroller/market_details_conteroller.dart';
import 'package:nft_shop/market/model/models.dart';
import 'package:nft_shop/market/page/details/works_transaction_records_page.dart';
import 'package:nft_shop/market/page/order/buy_confirm_order_page.dart';
import 'package:nft_shop/market/page/userinfo/user_info_page.dart';
import 'package:nft_shop/market/widget/market_share_widget.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/my/view/cast_hint.dart';
import 'package:nft_shop/my/view/my_check_work_widget.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/widgets/load_image.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';
import 'package:nft_shop/widgets/my_button.dart';
import 'package:nft_shop/widgets/my_scroll_view.dart';
import 'package:nft_shop/widgets/status_view.dart';
import 'package:nft_shop/util/other_utils.dart';
import 'package:share/share.dart';
import 'package:url_launcher/url_launcher.dart';

class WorksDetailsPage extends StatefulWidget {
  String id;
  int type; //1单个藏品详情 2整体铸造详情  3整体详情
  bool isHidePayment;

  WorksDetailsPage(
      {Key? key,
      required this.id,
      required this.type,
      this.isHidePayment = false})
      : super(key: key);

  @override
  _WorksDetailsPageState createState() => _WorksDetailsPageState();
}

class _WorksDetailsPageState extends State<WorksDetailsPage>
    with TickerProviderStateMixin {
  late TabController _tabController;
  final PageController _pageController = PageController(initialPage: 0);
  late MarketDetailsConteroller _conteroller;
  TimerUtil? _timerUtil;
  ConfigNameDetail? article;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(vsync: this, length: 3);
    _conteroller = MarketDetailsConteroller.to;
    _conteroller.type = widget.type;
    _conteroller.getDataList(widget.id);
    getConfigNameDetail("pay_is_open");
    LoginLogic.to.getUserInfoData();
  }

  void getConfigNameDetail(String name) async {
    try {
      List list = await ServiceRepository.getConfigNameDetail(name);
      list.forEach((element) {
        if (element.name.toString().trim() == name) {
          article = element;
        }
      });
    } catch (e, s) {}
    setState(() {});
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _tabController.dispose();
    cancelAddressTimer();
  }

  void cancelAddressTimer() {
    if (_timerUtil != null) {
      _timerUtil!.cancel();
      _timerUtil = null;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(48),
        child: AppBar(
          title: Text(
            "作品详情",
            style: TextStyle(
                fontSize: 16,
                color: Global.kTheme.textPrimary4,
                fontFamily: Global.mySemiboldFont),
          ),
          centerTitle: true,
          leading: IconButton(
            padding: const EdgeInsets.only(right: 12, top: 12, bottom: 12),
            icon: Image.asset(
              'assets/images/ic_back_black.png',
            ),
            onPressed: () {
              Get.back();
            },
          ),
          actions: [
            IconButton(
                icon: LoadAssetImage(
                  "na_share",
                  width: 16,
                  height: 16,
                ),
                onPressed: () {
                  if (!_conteroller.hasGoodsinfo) {
                    return;
                  }
                  showModalBottomSheet<void>(
                      context: context,

                      /// 禁止拖动关闭
                      enableDrag: false,

                      /// 使用true则高度不受16分之9的最高限制
                      isScrollControlled: true,
                      backgroundColor: Colors.transparent,
                      builder: (_) {
                        return MarketShareWidget(
                          info: _conteroller.goodsinfo,
                        );
                      });
                }),
          ],
        ),
      ),
      body: GetBuilder<MarketDetailsConteroller>(builder: (logic) {
        if (logic.status != LoadStatusType.success) {
          return StatusViews(logic.status);
        }

        if (logic.goodsinfo.info!.isPresell == 1) {
          if (logic.goodsinfo.info!.second! > 0) {
            cancelAddressTimer();
            _timerUtil =
                new TimerUtil(mTotalTime: logic.goodsinfo.info!.second! * 1000);
            _timerUtil!.setOnTimerTickCallback((int tick) {
              if (tick == 0) {
                cancelAddressTimer();
                setState(() {
                  logic.goodsinfo.info!.isPresell = 0;
                });
              }
              logic.setCountDownTime = Utils.constructTime(tick ~/ 1000);
            });
            // //开始倒计时
            _timerUtil!.startCountDown();
          }

          // if (DateUtil.getNowDateMs() <
          //     DateUtil.getDateMsByTimeStr(logic.goodsinfo.info!.sellTime!)!) {
          //   _timerUtil = new TimerUtil(
          //       mTotalTime: DateUtil.getDateMsByTimeStr(
          //               logic.goodsinfo.info!.sellTime!)! -
          //           DateUtil.getNowDateMs());
          //   _timerUtil!.setOnTimerTickCallback((int tick) {
          //     if (tick == 0) {
          //       cancelAddressTimer();
          //       setState(() {
          //         logic.goodsinfo.info!.isPresell = 0;
          //       });
          //     }
          //     logic.setCountDownTime = Utils.constructTime(tick ~/ 1000);
          //   });
          //   // //开始倒计时
          //   _timerUtil!.startCountDown();
          // }
        }

        return MyScrollView(
          children: [
            topWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            _basicInfoWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            // _framerWidget(),
            // Container(
            //   height: 10,
            //   color: Global.kTheme.colorLine,
            // ),
            _worksDescribeWidget(),
            // Container(
            //   height: 10,
            //   color: Global.kTheme.colorLine,
            // ),
            // if(widget.type != 2)transactionRecordWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            purchaseInformationWidget(),
            Container(
              height: MediaQuery.of(context).padding.bottom,
            ),
          ],
          bottomButton: widget.isHidePayment
              ? Container()
              : (widget.type != 2
                  ? Container(
                      height: 50 + ScreenUtil.getBottomBarH(context),
                      color: Colors.white,
                      child: Column(
                        children: [
                          Container(
                            padding: EdgeInsets.only(
                                left: 20, right: 15, top: 3, bottom: 3),
                            child: Row(
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Text.rich(TextSpan(children: [
                                  TextSpan(
                                      text: "¥",
                                      style: TextStyle(
                                          fontSize: 20,
                                          color: Global.kTheme.textPrimary4,
                                          fontFamily: Global.mySemiboldFont)),
                                  TextSpan(
                                      text: logic.goodsinfo.info!.price ?? "",
                                      style: TextStyle(
                                          fontSize: 20,
                                          color: Global.kTheme.textPrimary4,
                                          fontFamily: Global.mySemiboldFont)),
                                ])),
                                Spacer(),
                                logic.goodsinfo.info!.isPresell == 0
                                    ? Container(
                                        height: 38,
                                        width: 173,
                                        decoration: BoxDecoration(
                                          color: (article?.value == "false")
                                              ? Color(0xFFEFEFEF)
                                              : logic.goodsinfo.info!.num == 0
                                                  ? Color(0xFFEFEFEF)
                                                  : Global
                                                      .kTheme.colorBackground3,
                                          borderRadius:
                                              BorderRadius.circular(4),
                                        ),
                                        child: (article?.value == "false")
                                            ? MyButton(
                                                fontSize: 16,
                                                textColor:
                                                    Global.kTheme.textPrimary4,
                                                backgroundColor:
                                                    Color(0xFFEFEFEF),
                                                minHeight: 38,
                                                text: "敬请期待",
                                                onPressed: () {},
                                              )
                                            : MyButton(
                                                minHeight: 38,
                                                onPressed: logic.goodsinfo.info!
                                                            .num ==
                                                        0
                                                    ? () {
                                                        EasyLoading.showToast(
                                                            "已售罄");
                                                      }
                                                    : () {
                                                        if (UserController
                                                            .to.isLogin) {
                                                          if (UserController
                                                                  .to
                                                                  .loginuser
                                                                  ?.member
                                                                  ?.realNameStatus !=
                                                              "2") {
                                                            EasyLoading
                                                                .showToast(
                                                                    "请实名认证后购买");
                                                            return;
                                                          }
                                                          Get.to(
                                                              BuyConfirmOrderPage(
                                                            goodsinfo:
                                                                logic.goodsinfo,
                                                            type: 2,
                                                          ));
                                                        } else {
                                                          Get.to(LoginPage());
                                                        }
                                                      },
                                                text:
                                                    logic.goodsinfo.info!.num ==
                                                            0
                                                        ? "已售罄"
                                                        : "立即购买",
                                                fontSize: 16,
                                                textColor: logic.goodsinfo.info!
                                                            .num ==
                                                        0
                                                    ? Global.kTheme.textPrimary4
                                                    : Colors.white,
                                                backgroundColor:
                                                    logic.goodsinfo.info!.num ==
                                                            0
                                                        ? Color(0xFFEFEFEF)
                                                        : Global.kTheme
                                                            .colorBackground3,
                                              ),
                                      )
                                    : Container(
                                        height: 38,
                                        width: 210,
                                        decoration: BoxDecoration(
                                          color: Color(0xFFB2B2B2),
                                          borderRadius:
                                              BorderRadius.circular(4),
                                        ),
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.center,
                                          children: [
                                            Text(
                                              "敬请期待",
                                              style: TextStyle(
                                                  fontSize: 15,
                                                  color: Global
                                                      .kTheme.textPrimary5,
                                                  fontWeight: FontWeight.w600),
                                            ),
                                            // Text("${logic.goodsinfo.info!.sellTime??""}",style: TextStyle(fontSize: 12,color: Global.kTheme.textPrimary5,fontWeight: FontWeight.w600),),
                                            GetBuilder(
                                                init:
                                                    MarketDetailsConteroller(),
                                                id: "countDownTime",
                                                builder:
                                                    (MarketDetailsConteroller
                                                        c) {
                                                  return Text(
                                                    "${c.countDownTime} 后 开售",
                                                    style: TextStyle(
                                                        fontSize: 10,
                                                        color: Global.kTheme
                                                            .textPrimary5,
                                                        fontWeight:
                                                            FontWeight.w600),
                                                  );
                                                })
                                          ],
                                        ),
                                      )
                              ],
                            ),
                          ),
                          Spacer(),
                        ],
                      ),
                    )
                  : Container(
                      height: 40,
                      margin: EdgeInsets.only(
                          top: 5,
                          left: 14,
                          right: 14,
                          bottom: 22 + ScreenUtil.getBottomBarH(context)),
                      decoration: BoxDecoration(
                        color: Global.kTheme.colorBackground3,
                        borderRadius: BorderRadius.circular(4),
                      ),
                      child: MyButton(
                        minHeight: 50,
                        onPressed: () {
                          Utils.showElasticDialog<void>(
                            context: context,
                            barrierDismissible: false,
                            builder: (BuildContext context) {
                              return CasrHintDialog(
                                  price: logic.goodsinfo.info!.castPrice ?? "",
                                  id: "${logic.goodsinfo.info!.id ?? ""}");
                            },
                          );
                        },
                        text: "确认铸造",
                        fontSize: 16,
                        textColor: Colors.white,
                        backgroundColor: Global.kTheme.colorBackground3,
                      ),
                    )),
        );
      }),
    );
  }

  ///切换tabbar
  void _onPageChange(int index) {
    _tabController.animateTo(index);
    _conteroller.changeHeight(index);
  }

  ///详情头部信息
  Widget topWidget() {
    double height = Get.width * 350 / 375;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        InkWell(
          onTap: () {
            if (_conteroller.goodsinfo.info!.thumb!.isEmpty) {
              return;
            }
            Utils.showElasticDialog<void>(
              context: context,
              builder: (BuildContext context) {
                return MyCheckWorkWidget(
                    _conteroller.goodsinfo.info!.thumb ?? "");
              },
            );
          },
          child: Container(
            color: Global.kTheme.colorBackground5,
            child: LoadImage(
              _conteroller.goodsinfo.info!.thumb ?? "",
              width: double.infinity,
              height: height,
              fit: BoxFit.fitHeight,
            ),
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                _conteroller.goodsinfo.info!.title ?? "header_img",
                style: TextStyle(
                    fontSize: 16,
                    color: Global.kTheme.textPrimary4,
                    fontFamily: Global.mySemiboldFont),
              ),
              SizedBox(
                height: 8,
              ),
              Row(
                children: [
                  issueView(
                      "限量", _conteroller.goodsinfo.info!.allCount.toString()),
                  SizedBox(
                    width: 10,
                  ),
                  _objectType(
                      _conteroller.goodsinfo.info!.specialTypeName ?? ""),
                ],
              ),
              SizedBox(
                height: 10,
              ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  ClipRRect(
                      borderRadius: BorderRadius.circular(12),
                      child: LoadImage(
                        _conteroller.goodsinfo.info!.portrait ?? "",
                        width: 24,
                        height: 24,
                        holderImg: "header_img",
                      )),
                  SizedBox(
                    width: 5,
                  ),
                  Text(
                    _conteroller.goodsinfo.info!.nickname ?? "",
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontFamily: Global.mySemiboldFont,
                        fontSize: 14,
                        color: Global.kTheme.textPrimary0),
                  ),
                  SizedBox(
                    width: 5,
                  ),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          SizedBox(
                            height: 4,
                          ),
                          LoadAssetImage(
                            "icon_creation",
                            width: 4,
                            height: 5,
                          ),
                        ],
                      ),
                      Text(
                        "创作者",
                        style: TextStyle(
                            fontFamily: Global.mySemiboldFont,
                            fontSize: 12,
                            color: Color(0xFF1D6AEC)),
                      ),
                      Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          SizedBox(
                            height: 10,
                          ),
                          LoadAssetImage(
                            "icon_creation",
                            width: 4,
                            height: 5,
                          ),
                        ],
                      ),
                    ],
                  ),
                  Spacer(),
                  InkWell(
                    onTap: () {
                      print(
                          "id是--${_conteroller.goodsinfo.info!.framerMemberId ?? ""}");
                      Get.to(UserInfoPage(
                          ID: _conteroller.goodsinfo.info!.framerMemberId
                              .toString()));
                    },
                    child: Container(
                      child: Row(
                        children: [
                          Text(
                            "Ta的主页",
                            style: TextStyle(
                                fontSize: 12,
                                color: Global.kTheme.textPrimary3,
                                fontWeight: FontWeight.w600),
                          ),
                          SizedBox(
                            width: 5,
                          ),
                          LoadImage(
                            "icon_arrows",
                            width: 12,
                            height: 12,
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 5,
              ),
              if (widget.type != 2) collectionsView(),
            ],
          ),
        )
      ],
    );
  }

  ///收藏者
  Widget collectionsView() {
    ShouMemberInfo shou = _conteroller.goodsinfo.shouMemberInfo!;
    return Container(
      height: 40,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child: LoadImage(
                shou.portrait ?? "",
                width: 24,
                height: 24,
                holderImg: "header_img",
              )),
          SizedBox(
            width: 5,
          ),
          Text(
            shou.nickname ?? "",
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
                fontFamily: Global.mySemiboldFont,
                fontSize: 14,
                color: Global.kTheme.textPrimary0),
          ),
          SizedBox(
            width: 5,
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  SizedBox(
                    height: 4,
                  ),
                  LoadAssetImage(
                    "icon_collection",
                    width: 4,
                    height: 5,
                  ),
                ],
              ),
              Text(
                "收藏者",
                style: TextStyle(
                    fontFamily: Global.mySemiboldFont,
                    fontSize: 12,
                    color: Color(0xFFF17A47)),
              ),
              Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  SizedBox(
                    height: 10,
                  ),
                  LoadAssetImage(
                    "icon_collection",
                    width: 4,
                    height: 5,
                  ),
                ],
              ),
            ],
          ),
          SizedBox(
            width: 25,
          )
        ],
      ),
    );
  }

  ///基本信息
  Widget _basicInfoWidget() {
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: 14,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          cellTitleWidget("链上信息"),
          _infoTextItem(
              "所属专辑", _conteroller.goodsinfo.info!.specialAlbumName ?? ""),
          _infoTextItem("编      号",
              "#${_conteroller.goodsinfo.info!.code ?? ""}/${_conteroller.goodsinfo.info!.allCount ?? ""}"),
          _infoTextItem(
              "合约地址",
              // omitAddress(_conteroller.goodsinfo.info!.contractAddress ?? ""),
              omitAddress(_conteroller.goodsinfo.info!.contractAddress ??
                  (_conteroller.goodsinfo.info!.accountAddress ?? "")),
              // right: "查看合约",
              right: "复制地址", onTap: () {
            if (_conteroller.contract.length != 0) {
              // launch(_conteroller.contract);
              ClipboardData data = new ClipboardData(
                  // text: _conteroller.goodsinfo.info!.contractAddress ?? "");
                  text: _conteroller.goodsinfo.info!.contractAddress ??
                      (_conteroller.goodsinfo.info!.accountAddress ?? ""));
              Clipboard.setData(data);
              EasyLoading.showToast("复制成功");
            }
          }, copy: () {
            ClipboardData data = new ClipboardData(
                text: _conteroller.goodsinfo.info!.contractAddress ?? "");
            Clipboard.setData(data);
            EasyLoading.showToast("复制成功");
          }),
          _infoTextItem("链上标识", _conteroller.goodsinfo.info!.chainMark ?? ""),
          _infoTextItem("发布时间", _conteroller.goodsinfo.info!.createTime ?? ""),
          SizedBox(
            height: 15,
          ),
        ],
      ),
    );
  }

  ///基本信息Item
  Widget _infoTextItem(
    String title,
    String content, {
    String right = "",
    VoidCallback? onTap,
    VoidCallback? copy,
  }) {
    return Container(
      padding:
          title == "所属专辑" ? EdgeInsets.only(top: 5) : EdgeInsets.only(top: 15),
      child: Row(
        children: [
          Text(
            title,
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.inputHint1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            width: 15,
          ),
          Expanded(
            child: Row(
              children: [
                InkWell(
                    onTap: copy,
                    child: Container(
                        child: Text(
                      content,
                      style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary1,
                        fontFamily: Global.mySemiboldFont,
                      ),
                    ))),
                Spacer(),
                InkWell(
                  onTap: onTap,
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      right.length != 0
                          ? Text(
                              right,
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Global.kTheme.textPrimary3,
                                  fontFamily: Global.mySemiboldFont),
                            )
                          : Container(),
                      right.length != 0
                          ? SizedBox(
                              width: 3,
                            )
                          : Container(),
                      Visibility(
                        visible: right.length != 0,
                        child: LoadImage(
                          "icon_arrows",
                          width: 12,
                          height: 12,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  ///基本信息Item 合约地址
  Widget _infoTextAddressItem(
    String title,
    String content,
  ) {
    return Container(
      padding: EdgeInsets.only(top: 15),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text(
            title,
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.inputHint1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            width: 15,
          ),
          Text(
            omitAddress(content),
            style: TextStyle(
              fontSize: 12,
              color: Global.kTheme.textPrimary1,
              fontFamily: Global.mySemiboldFont,
            ),
          ),
        ],
      ),
    );
  }

  ///创作者介绍
  Widget _framerWidget() {
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: 14,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          cellTitleWidget("创作者介绍"),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ClipRRect(
                  borderRadius: BorderRadius.circular(21),
                  child: LoadImage(
                    _conteroller.goodsinfo.info!.portrait ?? "",
                    width: 42,
                    height: 42,
                  )),
              SizedBox(
                width: 5,
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      _conteroller.goodsinfo.info!.nickname ?? "",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          fontSize: 14,
                          color: Global.kTheme.textPrimary0,
                          fontFamily: Global.mySemiboldFont),
                    ),
                    InkWell(
                      onTap: () {
                        ClipboardData data = new ClipboardData(
                            text: _conteroller
                                    .goodsinfo.info!.framerAccountAddress ??
                                "");
                        Clipboard.setData(data);
                        EasyLoading.showToast("复制成功");
                      },
                      child: Row(
                        children: [
                          Text(
                            omitAddress(_conteroller
                                    .goodsinfo.info!.framerAccountAddress ??
                                ""),
                            maxLines: 1,
                            style: TextStyle(
                                fontSize: 12,
                                color: Global.kTheme.inputHint1,
                                fontFamily: Global.mySemiboldFont,
                                overflow: TextOverflow.ellipsis),
                          ),
                          SizedBox(
                            width: 4,
                          ),
                          LoadImage(
                            "my_copy",
                            width: 16,
                            height: 16,
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            _conteroller.goodsinfo.info!.introduce ?? "",
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.inputHint1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            height: 10,
          ),
        ],
      ),
    );
  }

  ///作品描述
  Widget _worksDescribeWidget() {
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: 14,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          cellTitleWidget("作品介绍"),
          Text(
            _conteroller.goodsinfo.info!.detail ?? "",
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.inputHint1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            height: 15,
          ),
        ],
      ),
    );
  }

  String omitAddress(String address, {int len = 4}) {
    if (address == null || address.isEmpty) return "";
    if (address.length > (len * 2)) {
      return address.substring(0, len) +
          '...' +
          address.substring(address.length - len, address.length);
    }
    return address;
  }

  //标题
  Widget cellTitleWidget(String title) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 14),
      child: Text(
        title,
        style: TextStyle(
            fontSize: 14,
            fontFamily: Global.mySemiboldFont,
            color: Global.kTheme.textPrimary1),
      ),
    );
  }

  ///交易记录
  Widget transactionRecordWidget() {
    double height = 0;
    if (_conteroller.goodsinfo.orderList!.length == 0) {
      height = 224;
    } else if (_conteroller.goodsinfo.orderList!.length <= 3) {
      height = _conteroller.goodsinfo.orderList!.length * 63 + 40;
    } else {
      height = 3 * 63 + 40;
    }
    return Container(
      height: height,
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Column(
        children: [
          InkWell(
            onTap: () => Get.to(WorksTransactionRecordsPage(
              type: 1,
              id: _conteroller.goodsinfo.info!.id!,
            )),
            child: Container(
              height: 40,
              child: Row(
                children: [
                  Text(
                    "交易记录",
                    style: TextStyle(
                        fontSize: 14,
                        color: Global.kTheme.textPrimary1,
                        fontFamily: Global.mySemiboldFont),
                  ),
                  Spacer(),
                  Text(
                    "更多交易记录",
                    style: TextStyle(
                        fontFamily: Global.mySemiboldFont,
                        fontSize: 12,
                        color: Global.kTheme.textPrimary3),
                  ),
                  SizedBox(
                    width: 5,
                  ),
                  LoadAssetImage(
                    "icon_arrows",
                    width: 12,
                    height: 12,
                  ),
                ],
              ),
            ),
          ),
          Expanded(child: Builder(builder: (context) {
            if (_conteroller.goodsinfo.orderList!.length == 0) {
              return StatusViews(LoadStatusType.empty);
            }
            return ListView.builder(
                physics: NeverScrollableScrollPhysics(), //禁止滑动
                itemCount: _conteroller.goodsinfo.orderList!.length > 3
                    ? 3
                    : _conteroller.goodsinfo.orderList!.length,
                itemBuilder: (context, int index) {
                  return transactionItem(
                      _conteroller.goodsinfo.orderList![index]);
                });
          })),
        ],
      ),
    );
  }

  Widget transactionItem(OrderList model) {
    return Container(
      padding: EdgeInsets.only(
        top: 15,
        bottom: 13,
      ),
      decoration: BoxDecoration(
          border: Border(
        bottom: Divider.createBorderSide(context,
            color: Global.kTheme.colorLine, width: 1),
      )),
      child: Row(
        children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  model.nickname ?? "",
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      fontSize: 12,
                      color: Global.kTheme.textPrimary1,
                      fontFamily: Global.mySemiboldFont),
                ),
                SizedBox(
                  height: 1,
                ),
                Text(
                  model.createTime ?? "",
                  style: TextStyle(
                      fontSize: 12,
                      color: Global.kTheme.textPrimary3,
                      fontFamily: Global.mySemiboldFont),
                ),
              ],
            ),
          ),
          Spacer(),
          Text(
            model.content ?? "",
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary1,
                fontFamily: Global.mySemiboldFont),
          ),
        ],
      ),
    );
  }

  ///购买须知
  Widget purchaseInformationWidget() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "购买须知",
            style: TextStyle(
                fontSize: 14,
                color: Global.kTheme.textPrimary1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            height: 9,
          ),
          // Text(
          //   "数字藏品为虚拟数字商品，而非实物，仅限经实名认证为年满14周岁的中国大陆用户购买。数字藏品的版权由发行方或原创者拥有，除另行取得版权拥有者书面同意外，用户不得将数字藏品用于任何商业用途。本商品一经售出，不支持退换。请勿对数字藏品进行炒作、场外交易、欺诈，或以任何其他非法方式进行使用",
          //   style: TextStyle(
          //       fontSize: 12,
          //       color: Global.kTheme.inputHint1,
          //       fontFamily: Global.mySemiboldFont),
          // ),
          PurchaseInWidget()
        ],
      ),
    );
  }

  ///藏品类型
  Widget _objectType(String state) {
    return Container(
      height: 20,
      decoration: BoxDecoration(
        color: Global.kTheme.colorBackground3,
      ),
      padding: EdgeInsets.symmetric(horizontal: 8, vertical: 1),
      child: Text(
        state,
        style: TextStyle(
            color: Global.kTheme.textPrimary5,
            fontSize: 12,
            fontFamily: Global.mySemiboldFont),
      ),
    );
  }

  //数量
  Widget issueView(String left, String right) {
    return Row(
      children: [
        Container(
          color: Global.kTheme.colorBackground3,
          padding: EdgeInsets.symmetric(horizontal: 5, vertical: 2),
          child: Text(
            left,
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary5,
                fontFamily: Global.mySemiboldFont),
          ),
        ),
        Container(
          color: Color(0xFFB6B6B6),
          padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
          child: Text(
            right,
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary5,
                fontFamily: Global.mySemiboldFont),
          ),
        ),
      ],
    );
  }
}
